﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApAPPLimitsViewModel
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System.ComponentModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

public class CApAPPLimitsViewModel : INotifyPropertyChanged
{
  private KiAppLimitsEx m_limits;
  private bool m_isLockTxCheckBoxChecked;
  private bool m_isLockTyCheckBoxChecked;
  private bool m_isLockTzCheckBoxChecked;
  private bool m_isLockRxCheckBoxChecked;
  private bool m_isLockRyCheckBoxChecked;
  private bool m_isLockRzCheckBoxChecked;
  private TxTransformation m_referenceFrame;

  public void CopyDataFromModel(CApAPPLimitsViewModel limitsViewModelToCopy)
  {
    if (limitsViewModelToCopy == null)
      return;
    this.Limits = limitsViewModelToCopy.Limits;
    this.IsLockTxCheckBoxChecked = limitsViewModelToCopy.IsLockTxCheckBoxChecked;
    this.IsLockTyCheckBoxChecked = limitsViewModelToCopy.IsLockTyCheckBoxChecked;
    this.IsLockTzCheckBoxChecked = limitsViewModelToCopy.IsLockTzCheckBoxChecked;
    this.IsLockRxCheckBoxChecked = limitsViewModelToCopy.IsLockRxCheckBoxChecked;
    this.IsLockRyCheckBoxChecked = limitsViewModelToCopy.IsLockRyCheckBoxChecked;
    this.IsLockRzCheckBoxChecked = limitsViewModelToCopy.IsLockRzCheckBoxChecked;
    this.ReferenceFrame = limitsViewModelToCopy.ReferenceFrame;
  }

  public void RaiseAllPropertiesChanged() => this.RaisePropertyChanged("Limits");

  public KiAppLimitsEx Limits
  {
    get => this.m_limits;
    set
    {
      this.m_limits = value;
      this.UpdateCheckBoxCheckedStatusForAllDofs();
      this.RaisePropertyChanged("TxMinValue");
      this.RaisePropertyChanged("TxMaxValue");
      this.RaisePropertyChanged("TyMinValue");
      this.RaisePropertyChanged("TyMaxValue");
      this.RaisePropertyChanged("TzMinValue");
      this.RaisePropertyChanged("TzMaxValue");
      this.RaisePropertyChanged("RxMinValue");
      this.RaisePropertyChanged("RxMaxValue");
      this.RaisePropertyChanged("RyMinValue");
      this.RaisePropertyChanged("RyMaxValue");
      this.RaisePropertyChanged("RzMinValue");
      this.RaisePropertyChanged("RzMaxValue");
      this.RaisePropertyChanged("IsTxLimitedOrLocked");
      this.RaisePropertyChanged("IsTyLimitedOrLocked");
      this.RaisePropertyChanged("IsTzLimitedOrLocked");
      this.RaisePropertyChanged("IsRxLimitedOrLocked");
      this.RaisePropertyChanged("IsRyLimitedOrLocked");
      this.RaisePropertyChanged("IsRzLimitedOrLocked");
      this.RaisePropertyChanged("IsRxPreviewButtonEnabled");
      this.RaisePropertyChanged("IsRyPreviewButtonEnabled");
      this.RaisePropertyChanged("IsRzPreviewButtonEnabled");
      this.RaisePropertyChanged("TxDofStatus");
      this.RaisePropertyChanged("TyDofStatus");
      this.RaisePropertyChanged("TzDofStatus");
      this.RaisePropertyChanged("RxDofStatus");
      this.RaisePropertyChanged("RyDofStatus");
      this.RaisePropertyChanged("RzDofStatus");
      this.RaisePropertyChanged("AreTxLimitsEditorsEnabled");
      this.RaisePropertyChanged("AreTyLimitsEditorsEnabled");
      this.RaisePropertyChanged("AreTzLimitsEditorsEnabled");
      this.RaisePropertyChanged("AreRxLimitsEditorsEnabled");
      this.RaisePropertyChanged("AreRyLimitsEditorsEnabled");
      this.RaisePropertyChanged("AreRzLimitsEditorsEnabled");
      this.RaisePropertyChanged(nameof (Limits));
    }
  }

  private void UpdateCheckBoxCheckedStatusForAllDofs()
  {
    if (this.m_limits == null)
      return;
    if (this.m_limits.TxDofStatus == 2)
      this.m_isLockTxCheckBoxChecked = true;
    if (this.m_limits.TyDofStatus == 2)
      this.m_isLockTyCheckBoxChecked = true;
    if (this.m_limits.TzDofStatus == 2)
      this.m_isLockTzCheckBoxChecked = true;
    if (this.m_limits.RxDofStatus == 2)
      this.m_isLockRxCheckBoxChecked = true;
    if (this.m_limits.RyDofStatus == 2)
      this.m_isLockRyCheckBoxChecked = true;
    if (this.m_limits.RzDofStatus != 2)
      return;
    this.m_isLockRzCheckBoxChecked = true;
  }

  public bool IsLockTxCheckBoxChecked
  {
    get => this.m_isLockTxCheckBoxChecked;
    set
    {
      this.m_isLockTxCheckBoxChecked = value;
      if (this.IsTxLimitedOrLocked)
        this.TxDofStatus = value ? (KiAppLimitDofStatus) 2 : (KiAppLimitDofStatus) 1;
      this.RaisePropertyChanged(nameof (IsLockTxCheckBoxChecked));
      this.RaisePropertyChanged("AreTxLimitsEditorsEnabled");
      this.RaisePropertyChanged("TxMinValue");
      this.RaisePropertyChanged("TxMaxValue");
    }
  }

  public bool IsLockTyCheckBoxChecked
  {
    get => this.m_isLockTyCheckBoxChecked;
    set
    {
      this.m_isLockTyCheckBoxChecked = value;
      if (this.IsTyLimitedOrLocked)
        this.TyDofStatus = value ? (KiAppLimitDofStatus) 2 : (KiAppLimitDofStatus) 1;
      this.RaisePropertyChanged(nameof (IsLockTyCheckBoxChecked));
      this.RaisePropertyChanged("AreTyLimitsEditorsEnabled");
      this.RaisePropertyChanged("TyMinValue");
      this.RaisePropertyChanged("TyMaxValue");
    }
  }

  public bool IsLockTzCheckBoxChecked
  {
    get => this.m_isLockTzCheckBoxChecked;
    set
    {
      this.m_isLockTzCheckBoxChecked = value;
      if (this.IsTzLimitedOrLocked)
        this.TzDofStatus = value ? (KiAppLimitDofStatus) 2 : (KiAppLimitDofStatus) 1;
      this.RaisePropertyChanged(nameof (IsLockTzCheckBoxChecked));
      this.RaisePropertyChanged("AreTzLimitsEditorsEnabled");
      this.RaisePropertyChanged("TzMinValue");
      this.RaisePropertyChanged("TzMaxValue");
    }
  }

  public bool IsTxLimitedOrLocked
  {
    get => this.TxDofStatus > 0;
    set
    {
      this.TxDofStatus = !value ? (KiAppLimitDofStatus) 0 : (!this.IsLockTxCheckBoxChecked ? (KiAppLimitDofStatus) 1 : (KiAppLimitDofStatus) 2);
      this.RaisePropertyChanged(nameof (IsTxLimitedOrLocked));
      this.RaisePropertyChanged("AreTxLimitsEditorsEnabled");
      this.RaisePropertyChanged("TxMinValue");
      this.RaisePropertyChanged("TxMaxValue");
    }
  }

  public bool IsTyLimitedOrLocked
  {
    get => this.TyDofStatus > 0;
    set
    {
      this.TyDofStatus = !value ? (KiAppLimitDofStatus) 0 : (!this.IsLockTyCheckBoxChecked ? (KiAppLimitDofStatus) 1 : (KiAppLimitDofStatus) 2);
      this.RaisePropertyChanged(nameof (IsTyLimitedOrLocked));
      this.RaisePropertyChanged("AreTyLimitsEditorsEnabled");
      this.RaisePropertyChanged("TyMinValue");
      this.RaisePropertyChanged("TyMaxValue");
    }
  }

  public bool IsTzLimitedOrLocked
  {
    get => this.TzDofStatus > 0;
    set
    {
      this.TzDofStatus = !value ? (KiAppLimitDofStatus) 0 : (!this.IsLockTzCheckBoxChecked ? (KiAppLimitDofStatus) 1 : (KiAppLimitDofStatus) 2);
      this.RaisePropertyChanged(nameof (IsTzLimitedOrLocked));
      this.RaisePropertyChanged("AreTzLimitsEditorsEnabled");
      this.RaisePropertyChanged("TzMinValue");
      this.RaisePropertyChanged("TzMaxValue");
    }
  }

  public bool IsLockRxCheckBoxChecked
  {
    get => this.m_isLockRxCheckBoxChecked;
    set
    {
      this.m_isLockRxCheckBoxChecked = value;
      if (this.IsRxLimitedOrLocked)
        this.RxDofStatus = value ? (KiAppLimitDofStatus) 2 : (KiAppLimitDofStatus) 1;
      this.RaisePropertyChanged(nameof (IsLockRxCheckBoxChecked));
      this.RaisePropertyChanged("AreRxLimitsEditorsEnabled");
      this.RaisePropertyChanged("IsRxPreviewButtonEnabled");
    }
  }

  public bool IsLockRyCheckBoxChecked
  {
    get => this.m_isLockRyCheckBoxChecked;
    set
    {
      this.m_isLockRyCheckBoxChecked = value;
      if (this.IsRyLimitedOrLocked)
        this.RyDofStatus = value ? (KiAppLimitDofStatus) 2 : (KiAppLimitDofStatus) 1;
      this.RaisePropertyChanged(nameof (IsLockRyCheckBoxChecked));
      this.RaisePropertyChanged("AreRyLimitsEditorsEnabled");
      this.RaisePropertyChanged("IsRyPreviewButtonEnabled");
    }
  }

  public bool IsLockRzCheckBoxChecked
  {
    get => this.m_isLockRzCheckBoxChecked;
    set
    {
      this.m_isLockRzCheckBoxChecked = value;
      if (this.IsRzLimitedOrLocked)
        this.RzDofStatus = value ? (KiAppLimitDofStatus) 2 : (KiAppLimitDofStatus) 1;
      this.RaisePropertyChanged(nameof (IsLockRzCheckBoxChecked));
      this.RaisePropertyChanged("AreRzLimitsEditorsEnabled");
      this.RaisePropertyChanged("IsRzPreviewButtonEnabled");
    }
  }

  public bool IsRxLimitedOrLocked
  {
    get => this.RxDofStatus > 0;
    set
    {
      this.RxDofStatus = !value ? (KiAppLimitDofStatus) 0 : (!this.IsLockRxCheckBoxChecked ? (KiAppLimitDofStatus) 1 : (KiAppLimitDofStatus) 2);
      this.RaisePropertyChanged(nameof (IsRxLimitedOrLocked));
      this.RaisePropertyChanged("AreRxLimitsEditorsEnabled");
      this.RaisePropertyChanged("IsRxPreviewButtonEnabled");
    }
  }

  public bool IsRyLimitedOrLocked
  {
    get => this.RyDofStatus > 0;
    set
    {
      this.RyDofStatus = !value ? (KiAppLimitDofStatus) 0 : (!this.IsLockRyCheckBoxChecked ? (KiAppLimitDofStatus) 1 : (KiAppLimitDofStatus) 2);
      this.RaisePropertyChanged(nameof (IsRyLimitedOrLocked));
      this.RaisePropertyChanged("AreRyLimitsEditorsEnabled");
      this.RaisePropertyChanged("IsRyPreviewButtonEnabled");
    }
  }

  public bool IsRzLimitedOrLocked
  {
    get => this.RzDofStatus > 0;
    set
    {
      this.RzDofStatus = !value ? (KiAppLimitDofStatus) 0 : (!this.IsLockRzCheckBoxChecked ? (KiAppLimitDofStatus) 1 : (KiAppLimitDofStatus) 2);
      this.RaisePropertyChanged(nameof (IsRzLimitedOrLocked));
      this.RaisePropertyChanged("AreRzLimitsEditorsEnabled");
      this.RaisePropertyChanged("IsRzPreviewButtonEnabled");
    }
  }

  public bool AreTxLimitsEditorsEnabled => this.TxDofStatus == 1;

  public bool AreTyLimitsEditorsEnabled => this.TyDofStatus == 1;

  public bool AreTzLimitsEditorsEnabled => this.TzDofStatus == 1;

  public bool AreRxLimitsEditorsEnabled => this.RxDofStatus == 1;

  public bool AreRyLimitsEditorsEnabled => this.RyDofStatus == 1;

  public bool AreRzLimitsEditorsEnabled => this.RzDofStatus == 1;

  public bool IsRxPreviewButtonEnabled
  {
    get => this.RxDofStatus == 1 && this.RxMinValue != this.RxMaxValue;
  }

  public bool IsRyPreviewButtonEnabled
  {
    get => this.RyDofStatus == 1 && this.RyMinValue != this.RyMaxValue;
  }

  public bool IsRzPreviewButtonEnabled
  {
    get => this.RzDofStatus == 1 && this.RzMinValue != this.RzMaxValue;
  }

  public double RxMinValue
  {
    get => this.Limits.RxDofStatus != 2 ? this.Limits.RxMinValue : 0.0;
    set
    {
      this.Limits.RxMinValue = value;
      this.RaisePropertyChanged(nameof (RxMinValue));
    }
  }

  public void SetRxMinValueIfNotLockedNoEventSent(double value)
  {
    if (this.Limits.RxDofStatus != 1)
      return;
    this.Limits.RxMinValue = value;
  }

  public double RxMaxValue
  {
    get => this.Limits.RxDofStatus != 2 ? this.Limits.RxMaxValue : 0.0;
    set
    {
      this.Limits.RxMaxValue = value;
      this.RaisePropertyChanged(nameof (RxMaxValue));
    }
  }

  public void SetRxMaxValueIfNotLockedNoEventSent(double value)
  {
    if (this.Limits.RxDofStatus != 1)
      return;
    this.Limits.RxMaxValue = value;
  }

  public double RyMinValue
  {
    get => this.Limits.RyDofStatus != 2 ? this.Limits.RyMinValue : 0.0;
    set
    {
      this.Limits.RyMinValue = value;
      this.RaisePropertyChanged(nameof (RyMinValue));
    }
  }

  public void SetRyMinValueIfNotLockedNoEventSent(double value)
  {
    if (this.Limits.RyDofStatus != 1)
      return;
    this.Limits.RyMinValue = value;
  }

  public double RyMaxValue
  {
    get => this.Limits.RyDofStatus != 2 ? this.Limits.RyMaxValue : 0.0;
    set
    {
      this.Limits.RyMaxValue = value;
      this.RaisePropertyChanged(nameof (RyMaxValue));
    }
  }

  public void SetRyMaxValueIfNotLockedNoEventSent(double value)
  {
    if (this.Limits.RyDofStatus != 1)
      return;
    this.Limits.RyMaxValue = value;
  }

  public double RzMinValue
  {
    get => this.Limits.RzDofStatus != 2 ? this.Limits.RzMinValue : 0.0;
    set
    {
      this.Limits.RzMinValue = value;
      this.RaisePropertyChanged(nameof (RzMinValue));
    }
  }

  public void SetRzMinValueIfNotLockedNoEventSent(double value)
  {
    if (this.Limits.RzDofStatus != 1)
      return;
    this.Limits.RzMinValue = value;
  }

  public double RzMaxValue
  {
    get => this.Limits.RzDofStatus != 2 ? this.Limits.RzMaxValue : 0.0;
    set
    {
      this.Limits.RzMaxValue = value;
      this.RaisePropertyChanged(nameof (RzMaxValue));
    }
  }

  public void SetRzMaxValueIfNotLockedNoEventSent(double value)
  {
    if (this.Limits.RzDofStatus != 1)
      return;
    this.Limits.RzMaxValue = value;
  }

  public double TxMinValue
  {
    get => this.Limits.TxDofStatus != 2 ? this.Limits.TxMinValue : 0.0;
    set
    {
      this.Limits.TxMinValue = value;
      this.RaisePropertyChanged(nameof (TxMinValue));
    }
  }

  public double TxMaxValue
  {
    get => this.Limits.TxDofStatus != 2 ? this.Limits.TxMaxValue : 0.0;
    set
    {
      this.Limits.TxMaxValue = value;
      this.RaisePropertyChanged(nameof (TxMaxValue));
    }
  }

  public double TyMinValue
  {
    get => this.Limits.TyDofStatus != 2 ? this.Limits.TyMinValue : 0.0;
    set
    {
      this.Limits.TyMinValue = value;
      this.RaisePropertyChanged(nameof (TyMinValue));
    }
  }

  public double TyMaxValue
  {
    get => this.Limits.TyDofStatus != 2 ? this.Limits.TyMaxValue : 0.0;
    set
    {
      this.Limits.TyMaxValue = value;
      this.RaisePropertyChanged(nameof (TyMaxValue));
    }
  }

  public double TzMinValue
  {
    get => this.Limits.TzDofStatus != 2 ? this.Limits.TzMinValue : 0.0;
    set
    {
      this.Limits.TzMinValue = value;
      this.RaisePropertyChanged(nameof (TzMinValue));
    }
  }

  public double TzMaxValue
  {
    get => this.Limits.TzDofStatus != 2 ? this.Limits.TzMaxValue : 0.0;
    set
    {
      this.Limits.TzMaxValue = value;
      this.RaisePropertyChanged(nameof (TzMaxValue));
    }
  }

  public KiAppLimitDofStatus TxDofStatus
  {
    get => this.Limits.TxDofStatus;
    set
    {
      this.Limits.TxDofStatus = value;
      this.RaisePropertyChanged(nameof (TxDofStatus));
      this.RaisePropertyChanged("TxMinValue");
      this.RaisePropertyChanged("TxMaxValue");
    }
  }

  public KiAppLimitDofStatus TyDofStatus
  {
    get => this.Limits.TyDofStatus;
    set
    {
      this.Limits.TyDofStatus = value;
      this.RaisePropertyChanged(nameof (TyDofStatus));
      this.RaisePropertyChanged("TyMinValue");
      this.RaisePropertyChanged("TyMaxValue");
    }
  }

  public KiAppLimitDofStatus TzDofStatus
  {
    get => this.Limits.TzDofStatus;
    set
    {
      this.Limits.TzDofStatus = value;
      this.RaisePropertyChanged(nameof (TzDofStatus));
      this.RaisePropertyChanged("TzMinValue");
      this.RaisePropertyChanged("TzMaxValue");
    }
  }

  public KiAppLimitDofStatus RxDofStatus
  {
    get => this.Limits.RxDofStatus;
    set
    {
      this.Limits.RxDofStatus = value;
      this.RaisePropertyChanged(nameof (RxDofStatus));
      this.RaisePropertyChanged("RxMinValue");
      this.RaisePropertyChanged("RxMaxValue");
    }
  }

  public KiAppLimitDofStatus RyDofStatus
  {
    get => this.Limits.RyDofStatus;
    set
    {
      this.Limits.RyDofStatus = value;
      this.RaisePropertyChanged(nameof (RyDofStatus));
      this.RaisePropertyChanged("RyMinValue");
      this.RaisePropertyChanged("RyMaxValue");
    }
  }

  public KiAppLimitDofStatus RzDofStatus
  {
    get => this.Limits.RzDofStatus;
    set
    {
      this.Limits.RzDofStatus = value;
      this.RaisePropertyChanged(nameof (RzDofStatus));
      this.RaisePropertyChanged("RzMinValue");
      this.RaisePropertyChanged("RzMaxValue");
    }
  }

  public TxTransformation ReferenceFrame
  {
    get => this.m_referenceFrame;
    set
    {
      this.m_referenceFrame = value;
      this.RaisePropertyChanged(nameof (ReferenceFrame));
    }
  }

  private void RaisePropertyChanged(string property)
  {
    if (this.PropertyChanged == null)
      return;
    this.PropertyChanged((object) this, new PropertyChangedEventArgs(property));
  }

  public event PropertyChangedEventHandler PropertyChanged;
}
